package cn.domypay.back.base.impl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.domypay.back.base.BaseDao;
import cn.domypay.back.base.BaseObj;
import cn.domypay.back.exception.DoMyPayException;

public class BaseDaoImpl extends SqlMapClientDaoSupport implements BaseDao{

	/**
	 * Get list info by sqlMap
	 * @param obj
	 * @param sqlMapID
	 * @return
	 * @throws NetosException
	 */
	public List<BaseObj> getList(BaseObj obj,String sqlMapID) throws DoMyPayException{
		
		return this.getSqlMapClientTemplate().queryForList(sqlMapID,obj);
	}
	
	
	/**
	 * 获取前N条数据集合
	 */
	public List<BaseObj> getTopList(BaseObj obj, String sqlMapId,int start, int end) throws DoMyPayException
	{
		return this.getSqlMapClientTemplate().queryForList(sqlMapId, obj, start, end);
	}
	/**
	 * Get list by sqlMapId
	 * @param obj
	 * @param sqlMapId
	 * @param searchVO
	 * @return
	 * @throws NetosException
	 */
//	public List getList(BaseObj obj,String sqlMapId, SearchVO searchVO) {
//		
//		if(searchVO==null){
//			return this.getSqlMapClientTemplate().queryForList(sqlMapId,obj);
//		}else{
//			String count = String.valueOf(this.getSqlMapClientTemplate().queryForObject(sqlMapId+"Count",obj));
//				
//			int totalRecord = Integer.valueOf( count ==null ? "0" : count);
//				
//			List resultList = this.getSqlMapClientTemplate().queryForList(sqlMapId, obj, (searchVO.getCurrentPage()-1)*searchVO.getPageSize(), searchVO.getPageSize());
//				
//			int countPage = (int) Math.ceil((totalRecord + searchVO.getPageSize() - 1) / searchVO.getPageSize());
//				
//			searchVO.setMaxPage(countPage == 0 ? 1 : countPage);
//				
//			searchVO.setTotalRecord(totalRecord);
//			/**
//			 * 分页处理
//			 */
//			PaginatedListWrapper.doPage(searchVO);
//				
//			return resultList;
//		}
//			
//	}
	
	public String getCount(BaseObj object,String sqlMapId) throws DoMyPayException
	{
		 return String.valueOf(this.getSqlMapClientTemplate().queryForObject(sqlMapId, object));
	}

	/**
	 * add by sqlMapId
	 * @param obj
	 * @param sqlMapId
	 * @return
	 * @throws NetosException
	 */
	public String add(BaseObj obj,String sqlMapId) throws DoMyPayException{
		return (String)this.getSqlMapClientTemplate().insert(sqlMapId,obj);
	}

	/**
	 * Modify by sqlMapId
	 * @param obj
	 * @param sqlMapId
	 * @throws NetosException
	 */
	public void modify(BaseObj obj,String sqlMapId) throws DoMyPayException{
		this.getSqlMapClientTemplate().update(sqlMapId,obj);
	}
	
	/**
	 * Delete by sqlMap Id
	 * @param obj
	 * @param sqlMapId
	 * @throws NetosException
	 */
	public void delete(BaseObj obj,String sqlMapId) throws DoMyPayException{
		this.getSqlMapClientTemplate().delete(sqlMapId,obj);
	}
	/**
	 * Delete by sqlMapID
	 * @param parameter
	 * @param sqlMapId
	 * @throws NetosException
	 */
	
	public void delete(String parameter,String sqlMapId) throws DoMyPayException{
			this.getSqlMapClientTemplate().delete(sqlMapId,parameter);
	}
	
	/**
	 * Get object by sqlMap
	 * @param obj PObject
	 * @param sqlMapId ibatis sqlmap Id
	 * @return
	 * @throws NetosException
	 */
	public BaseObj getObject(BaseObj obj,String sqlMapId) throws DoMyPayException{
		return (BaseObj)this.getSqlMapClientTemplate().queryForObject(sqlMapId,obj);
	}
	/**
	 * Get object by sqlMap
	 * @param Id  recordId
	 * @param sqlMapID ibatis sqlmap Id
	 * @return
	 * @throws NetosException
	 */
	public BaseObj getObject(String parameter,String sqlMapID) throws DoMyPayException{
		return (BaseObj)this.getSqlMapClientTemplate().queryForObject(sqlMapID,parameter);
	}
	
	/**
	 * Get list by parameter
	 * @param parameter
	 * @param sqlMapID
	 * @return
	 * @throws NetosException
	 */
	public List getList(String parameter,String sqlMapID) throws DoMyPayException{
		return this.getSqlMapClientTemplate().queryForList(sqlMapID,parameter);
	}

	/**
	 * Get list by sql
	 * @param sqlMapID
	 * @return
	 */
	public List getList(String sqlMapID) throws DoMyPayException
	{
		return this.getSqlMapClientTemplate().queryForList(sqlMapID);
	}
	
	/**
	 * Modify by sqlMapId
	 * @param parameter
	 * @param sqlMapId
	 * @throws NetosException
	 */
	public void modify(String parameter,String sqlMapId) throws DoMyPayException{
		this.getSqlMapClientTemplate().update(sqlMapId,parameter);
	}
}
